package assignment2;
//Author Mark Mckillion, Date Completed 09/12/2011

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@SuppressWarnings("serial")
public class CollectionMenu extends JFrame
{   /*The purpose of this class it to display a menu.
     *The user can decide the type of collection they wish to initialize.
     *The frame will have a label and two buttons.*/
    
    private JButton jButton1, jButton2;
    private JLabel jLabel1;
    
    {   //sets a title to the frame.
        this.setTitle("Mark Mckillion - B00540772");
        
        //sets the program to close when the "X" is pressed.
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        
        //creates the elements of the menu.
        jLabel1 = new JLabel();
        jButton1 = new JButton();
        jButton2 = new JButton();
        
        //choose the font for the label, to instruct the user how to interact.
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("Choose a Collection Type");

        //set text to the buttons so the user knows what collection will be opened when pressed.
        jButton1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jButton1.setText("Stack");
        jButton2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jButton2.setText("Queue");
        
        //create action listeners for the buttons.
        class MenuListener1 implements ActionListener
        {   @Override
            public void actionPerformed (ActionEvent ae)
            {   //the first listener will set the stack frame as visible.
                StackFrame stack = new StackFrame();
                stack.setVisible(true);
            }
        }
        
        //create an action listener for the second button.
        class MenuListener2 implements ActionListener
        {   @Override
            public void actionPerformed (ActionEvent ae)
            {   //the second listener will set the queue frame as visible.
                QueueFrame queue = new QueueFrame();
                queue.setVisible(true);
            }
        }
        
        //add the action listeners to the buttons.
        jButton1.addActionListener(new MenuListener1());
        jButton2.addActionListener(new MenuListener2());
        
        //used a swing GUI form to create the GroupLayout, and copied the source code.
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(76, 76, 76)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(123, 123, 123)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(86, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(63, Short.MAX_VALUE))
        ); pack();
    }
}